import React, { Component } from 'react';
import axios from "../../../../../../../../util/axios"
import "./index.css"
import { Pagination, Switch, Select, Input } from 'antd';
const { Option } = Select
const { Search } = Input;
class Live_streaming extends Component {

    state = {
        list: [],
        isShow: false,
        total: 0
    };
    componentWillMount() {

    }
    componentDidMount() {
        this.getlive()
    }

    getlive(current, pageSize) {
        // console.log(current, pageSize, "asd")
        axios.get("/livedata", {
            params: {
                pindex: current ? current : 1,
                psize: 10,
            }
        }).then(res => {
            console.log(res.data.data)
            this.setState(
                {
                    list: res.data.data,
                    total:res.data.total,
                }
            )

            // this.setState(
            //     this.state.total = res.data.total,
            // )
        })
    }


    render() {
        //点击分页
        const pageChange = (current, pageSize) => {
            console.log(current, pageSize)
            this.getlive(current, pageSize)
        }

        //swith开关
        const onChange = (check) => {
            console.log(check)
        }

        //进入直播页
        const pushlive = (item) => {
            console.log(item)
            this.props.history.push({ pathname: "/pushlive", state: { item } })
        }

        //筛选

        const handleChange = (value) => {
            console.log(value)
            axios.get("/livesou", {
                params: {
                    sou: value
                }
            }).then(res => {
                console.log(res,"筛选")
                this.setState({
                    list: res.data.data,
                    total:res.data.total,
                }

                )
            })
        }
        //搜索
        const onSearch = (check) => {
            console.log(check)
            axios.get("/livesou", {
                params: {
                    name: check
                }
            }).then(res => {
                console.log(res)
                this.setState(
                    { list: res.data.data,total:res.data.total, }
                )
            })
        }

        //点击删除
        const dellive = (key) => {
            console.log(key, "aaaa")
            axios.get("/livedleat", { params: { id: key } }).then(res => { console.log(res) })
            this.getlive()
            
        }
        return (
            this.state.list.map(item => {
                return item.lls = JSON.parse(item.lls)
            }),
            console.log(this.state.list),
            <div className="box">
                <div className="content">
                    <div style={{ paddingTop: "20px" }}>
                        <span>直播状态：</span>
                        <Select defaultValue="全部" style={{ width: 120 }} onChange={handleChange}>
                            <Option value="正在直播">正在直播</Option>
                            <Option value="已结束">已结束</Option>
                            <Option value="全部">全部</Option>
                        </Select>

                        <span style={{ paddingLeft: 80 }}>商品搜索：</span>
                        <Search placeholder="input search text" onSearch={onSearch} style={{ width: 200 }} />
                    </div>
                    <ul>
                        {
                            this.state.list.map((item, index) => {
                                return <div key={index}>
                                    <li>
                                        <img src={item.img} alt="" />
                                        <p>{item.title}</p>
                                        <p><span>{item.name}</span><span className="span2">2021.12.12</span></p>
                                        <p><span className="span3" onClick={() => { pushlive(item) }}>进入直播</span><Switch checked={item.lls} onChange={onChange} /></p>
                                        <p><span className="span4" onClick={() => { dellive(item.id) }}>删除</span></p>
                                    </li>
                                </div>
                            })
                        }
                    </ul>
                </div>
                <Pagination defaultCurrent={1} defaultPageSize={10} total={this.state.total} onChange={pageChange} className="Pagination" />
            </div>

        );
    }
}

export default Live_streaming;
